<template>
  <Form
    ref="saleTargetForm"
    :model="form"
    :rules="rules"
    @keydown.enter.native="handleSubmit"
    inline
    style="width: 100%">
    <FormItem prop="date">
      <DatePicker type="date" placeholder="请选择创建日期" v-model="form.date"></DatePicker>
    </FormItem>
    <FormItem style="float: right">
      <Button @click="handleSubmit" icon="md-search" type="primary">
        搜索
      </Button>
    </FormItem>
  </Form>
</template>
<script>
import {
  mapState,
  mapActions,
  mapMutations
} from 'vuex'
export default {
  name: 'SaleTargetForm',
  props: {
    dateRules: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data () {
    return {
      form: {
        date: ''
      }
    }
  },
  computed: {
    rules () {
      return {
        date: this.dateRules
      }
    }
  },
  methods: {
    handleSubmit () {
      this.$refs.saleTargetForm.validate((valid) => {
        if (valid) {
          this.$emit('on-success-valid', {
            ctime: this.form.date ? this.$moment(this.form.date).format('YYYY-MM-DD HH:mm:ss') : ''
          })
        }
      })
    }
  }
}
</script>
